﻿using mfLogger;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections;

namespace mfLogger.Test
{
    
    
    /// <summary>
    ///This is a test class for mfLogMessageCollectionTest and is intended
    ///to contain all mfLogMessageCollectionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class mfLogMessageCollectionTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for mfLogMessageCollection Constructor
        ///</summary>
        [TestMethod()]
        public void mfLogMessageCollectionConstructorTest()
        {
            int capacity = 10; 

            mfLogMessageCollection target = new mfLogMessageCollection(capacity);

            Assert.AreEqual(capacity+1, target.Capacity);
        }

        /// <summary>
        ///A test for Add
        ///</summary>
        [TestMethod()]
        public void FirstFill_AddTest()
        {
            int capacity = 10; 
            mfLogMessageCollection target = new mfLogMessageCollection(capacity);

            var msgs = new ArrayList();

            for (int i = 0; i < capacity; i++)
            {
                mfLogMessage value = new mfLogMessage((i+1).ToString());
                var insertedI = target.Add(value);
                msgs.Add(value);

                Assert.AreEqual(i, insertedI);
            }

            for (int i = 0; i < capacity; i++)
            {
                Assert.AreEqual(msgs[i].ToString(), target[i].ToString());
            }
        }

        /// <summary>
        ///A test for Add
        ///</summary>
        [TestMethod()]
        public void ReFill_AddTest()
        {
            int capacity = 10;
            mfLogMessageCollection target = new mfLogMessageCollection(capacity);

            var msgs = new ArrayList();

            for (int i = 0; i < capacity+3; i++)
            {
                mfLogMessage value = new mfLogMessage((i + 1).ToString());
                var insertedI = target.Add(value);
                msgs.Add(value);

                Assert.AreEqual((i%capacity), insertedI);
            }

            msgs.RemoveAt(0);
            msgs.RemoveAt(0);
            msgs.RemoveAt(0);

            Assert.AreEqual(msgs[0].ToString(), target[0].ToString());
            Assert.AreEqual(msgs[1].ToString(), target[1].ToString());
            Assert.AreEqual(msgs[2].ToString(), target[2].ToString());
            Assert.AreEqual(msgs[3].ToString(), target[3].ToString());
            Assert.AreEqual(msgs[4].ToString(), target[4].ToString());
            Assert.AreEqual(msgs[5].ToString(), target[5].ToString());
            Assert.AreEqual(msgs[6].ToString(), target[6].ToString());
            Assert.AreEqual(msgs[7].ToString(), target[7].ToString());
            Assert.AreEqual(msgs[8].ToString(), target[8].ToString());
            Assert.AreEqual(msgs[9].ToString(), target[9].ToString());
        }

        /// <summary>
        ///A test for Add
        ///</summary>
        //[TestMethod()]
        public void ReReFill_AddTest()
        {
            //TODO: implement ReReFill_AddTest
            throw new NotImplementedException();
        }

        /// <summary>
        ///A test for Clear
        ///</summary>
        [TestMethod()]
        public void ClearTest()
        {
            int capacity = 10; 
            mfLogMessageCollection target = new mfLogMessageCollection(capacity);

            target.Add(new mfLogMessage("1"));

            Assert.AreEqual(1, target.Count);
            target.Clear();
            Assert.AreEqual(0, target.Count);
        }

        /// <summary>
        ///A test for Contains
        ///</summary>
        [TestMethod()]
        public void ContainsTest()
        {
            int capacity = 10; 
            mfLogMessageCollection target = new mfLogMessageCollection(capacity); 
            mfLogMessage item = new mfLogMessage("1"); 

            bool expected = true; 
            bool actual;

            target.Add(item);
            actual = target.Contains(item);

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Capacity
        ///</summary>
        [TestMethod()]
        public void CapacityChangeTest()
        {
            int capacity = 5; 
            mfLogMessageCollection target = new mfLogMessageCollection(capacity); 

            int expected = 10; 
            int actual;

            target.Capacity = expected;
            actual = target.Capacity;

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, target.Count);
        }

   
    }
}
